package springTest;

import com.baidu.aip.face.AipFace;
import org.json.JSONObject;
import org.junit.Test;

import java.util.HashMap;

public class Aip {


    //设置APPID/AK/SK
    public static final String APP_ID = "25360256";
    public static final String API_KEY = "77pGiwFSfy01VzozUihOiDYz";
    public static final String SECRET_KEY = "RS0S13AipV5MrUkYk0Sjxvdzy76Lr5Sg";

    @Test
    public void testAip() {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 调用接口
        String image = "https://xuzy-tanhua.oss-cn-beijing.aliyuncs.com/2021/12/16/6acf0fcc-99bc-4b62-8721-4e417bbff5dc.jpg";
        String imageType = "URL";

        HashMap<String, String> options = new HashMap<>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "NONE");

        // 人脸检测
        JSONObject res = client.detect(image, imageType, options);
        System.out.println(res.toString(2));
        System.out.println("qweerqwrerwq");
    }

    }


